package net.confinanz.client.data;

import java.sql.Date;

public class Datum extends Date {

	private static final long serialVersionUID = -6100988198519414233L;
	
	
	public Datum(long l) {
		super(l);
	}
		
	public String getTag() {
		return super.toString().substring(8, 9);
	}
	
	public String getMonat() {
		return super.toString().substring(5, 6);
	}
	
	public String getJahr() {
		return super.toString().substring(0, 3);
	}
	
	@Override
	public String toString() {
		char[] chars = super.toString().toCharArray();
		char[] date = new char[10];
		date[0] = chars[8];
		date[1] = chars[9];
		date[2] = '.';
		date[3] = chars[5];
		date[4] = chars[6];
		date[5] = '.';
		date[6] = chars[0];
		date[7] = chars[1];
		date[8] = chars[2];
		date[9] = chars[3];
		return String.valueOf(date);
	}
	
	public String toSqlString() {
		return super.toString();
	}
	
	
	public static Datum valueOfSql(String s) {
		Date date = Date.valueOf(s);
		return new Datum(date.getTime());
	}
	
	public static Datum valueOf(String s) {
		char[] chars = s.toCharArray();
		char[] datum = new char[10];
		datum[0] = chars[6];
		datum[1] = chars[7];
		datum[2] = chars[8];
		datum[3] = chars[9];
		datum[4] = '-';
		datum[5] = chars[3];
		datum[6] = chars[4];
		datum[7] = '-';
		datum[8] = chars[0];
		datum[9] = chars[1];

		Date date = Date.valueOf(String.valueOf(datum));
		return new Datum(date.getTime());
	}
}